class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        sort(intervals.begin(), intervals.end());
        vector<vector<int>> ret;
        int left = intervals[0][0], right = intervals[0][1];
        for(auto& e : intervals)
        {
            if(e[0] <= right) // 可以合并
            {
                right = max(right, e[1]);
            }
            else
            {
                ret.push_back({left, right});
                left = e[0], right = e[1];
            }
        }
        ret.push_back({left, right});
        return ret;
    }
};